package com.mpgame.database.mysql.mapper.game;

import com.mpgame.database.mysql.mapper.BaseMapper;
import com.mpgame.database.mysql.model.game.Players;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface PlayersMapper extends BaseMapper<Players> {
    
    @Insert("INSERT INTO players (account_id, name, title_id, coin) VALUES (#{accountId}, #{name}, #{titleId}, #{coin})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Players players);

    @Select("SELECT * FROM players WHERE id = #{id}")
    Players selectById(@Param("id") int id);

    @Select("SELECT * FROM players WHERE account_id = #{accountId}")
    Players selectByAccountId(@Param("accountId") int accountId);

    @Select("SELECT * FROM players WHERE name = #{name}")
    Players selectByName(@Param("name") String name);

    @Select("SELECT * FROM players")
    List<Players> selectAll();

    @Update("UPDATE players SET name = #{name}, title_id = #{titleId}, coin = #{coin} WHERE id = #{id}")
    int updateById(Players players);

    @Update("UPDATE players SET coin = #{coin} WHERE id = #{id}")
    int updateCoin(@Param("id") int id, @Param("coin") int coin);
}
